package org.shangrila.app.wechat.service;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.shangrila.app.wechat.menu.LevelMenu;
import org.shangrila.app.wechat.menu.Menu;
import org.shangrila.app.wechat.menu.MenuButton;
import org.shangrila.app.wechat.menu.MenuUtil;
import org.shangrila.app.wechat.menu.SubMenuButton;
import org.shangrila.app.wechat.utils.WeChatHttpUtil;

@Controller
@RequestMapping("/wechat")
public class MenuController {

	/**
	 * 创建菜单
	 */
	@RequestMapping("/createMenu")
	public void createMenu() {
		WeChatHttpUtil.createMenu(getMenu());
	}

	/**
	 * 定义菜单属性
	 * 
	 * @return
	 */
	private Menu getMenu() {
		Menu menu = new Menu();

		// 建3个导航菜单
		LevelMenu tLevelMenuOne = new LevelMenu();
		tLevelMenuOne.setName("测试1");
		tLevelMenuOne.setType(MenuUtil.MENU_TYPE_CLICK);
		LevelMenu tLevelMenuTwo = new LevelMenu();
		tLevelMenuTwo.setName("测试2");
		tLevelMenuTwo.setType(MenuUtil.MENU_TYPE_CLICK);
		LevelMenu tLevelMenuThree = new LevelMenu();
		tLevelMenuThree.setName("测试3");
		tLevelMenuThree.setType(MenuUtil.MENU_TYPE_CLICK);

		// 第一个导航菜单的子菜单
		SubMenuButton tSubMenuButton_oneone = new SubMenuButton();
		tSubMenuButton_oneone.setType(MenuUtil.MENU_TYPE_CLICK);
		tSubMenuButton_oneone.setName("点击11");
		tSubMenuButton_oneone.setKey("11");

		SubMenuButton tSubMenuButton_onetwo = new SubMenuButton();
		tSubMenuButton_onetwo.setType(MenuUtil.MENU_TYPE_CLICK);
		tSubMenuButton_onetwo.setName("点击12");
		tSubMenuButton_onetwo.setKey("12");

		// 加入导航菜单
		tLevelMenuOne.setSub_button(new SubMenuButton[] { tSubMenuButton_oneone, tSubMenuButton_onetwo });

		// 第二 个导航菜单的子菜单
		SubMenuButton tSubMenuButton_twoone = new SubMenuButton();
		tSubMenuButton_twoone.setType(MenuUtil.MENU_TYPE_CLICK);
		tSubMenuButton_twoone.setName("点击21");
		tSubMenuButton_twoone.setKey("21");

		SubMenuButton tSubMenuButton_twotwo = new SubMenuButton();
		tSubMenuButton_twotwo.setType(MenuUtil.MENU_TYPE_CLICK);
		tSubMenuButton_twotwo.setName("点击22");
		tSubMenuButton_twotwo.setKey("22");

		SubMenuButton tSubMenuButton_twothree = new SubMenuButton();
		tSubMenuButton_twothree.setType(MenuUtil.MENU_TYPE_CLICK);
		tSubMenuButton_twothree.setName("点击23");
		tSubMenuButton_twothree.setKey("23");

		// 加入导航菜单
		tLevelMenuTwo.setSub_button(
				new SubMenuButton[] { tSubMenuButton_twoone, tSubMenuButton_twotwo, tSubMenuButton_twothree });

		// 第三个导航菜单的子菜单
		SubMenuButton tSubMenuButton_threeone = new SubMenuButton();
		tSubMenuButton_threeone.setType(MenuUtil.MENU_TYPE_CLICK);
		tSubMenuButton_threeone.setName("点击31");
		tSubMenuButton_threeone.setKey("31");

		SubMenuButton tSubMenuButton_threetwo = new SubMenuButton();
		tSubMenuButton_threetwo.setType(MenuUtil.MENU_TYPE_CLICK);
		tSubMenuButton_threetwo.setName("点击32");
		tSubMenuButton_threetwo.setKey("32");

		// 加入导航菜单
		tLevelMenuThree.setSub_button(new SubMenuButton[] { tSubMenuButton_threeone, tSubMenuButton_threetwo });

		menu.setButton(new MenuButton[] { tLevelMenuOne, tLevelMenuTwo, tLevelMenuThree });

		return menu;

	}
}
